using System;
using System.Collections.Generic;
using System.Text;
using Wrath.Xml;
using Wrath.RuleForge.Interfaces;
using System.ComponentModel;

namespace Wrath.RuleForge.Property
{
    public class DieWrapper : IPropertyWrapper<Element>
    {
        private bool hasChanged;
        private Element element;

        private Wrath.Xml.Attribute nameAttribute;
        private Element iconElement;
        private Element positionElement;

        [ReadOnly(true)]
        [Category("Die")]
        [Description("The name of the built-in die. (d4, d6, d8, d10, d12, d20, d100 or dmdie)")]
        public string Name { get { return nameAttribute.Value; } set { nameAttribute.Value = value; } }

        [Category("Die")]
        [Description("The icon to use in the chatwindow when the die is rolled.")]
        public string Icon { get { return iconElement.Value; } set { iconElement.Value = value; } }

        [Category("Die")]
        [Description("The initial starting position (x,y) of the die on the desktop. A negative value seems to be measured from the opposite edge. Eg. A -10 y value is 10 pixels from the bottom of the desktop.")]
        public string Position { get { if (positionElement != null) return positionElement.Value; return "None."; } set { if (positionElement != null) positionElement.Value = value; } }

        public DieWrapper(Element element)
        {
            hasChanged = false;
            this.element = element;

            nameAttribute = element.FindAttribute("name");
            iconElement = element.FindFirstElement("icon", false);
            positionElement = element.FindFirstElement("position", false);
        }

        #region IPropertyWrapper<Element> Members

        [Browsable(false)]
        public bool HasChanged
        {
            get
            {
                return hasChanged;
            }
            set
            {
                hasChanged = value;
            }
        }

        [Browsable(false)]
        public Element Data
        {
            get { return element; }
        }

        #endregion
    }
}
